package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.entity.ApArticleContent;
import com.heima.article.mapper.ApArticleContentMapper;
import com.heima.article.service.ApArticleContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import static net.sf.jsqlparser.parser.feature.Feature.insert;

/**
 * <p>
 * APP已发布文章内容表 服务实现类
 * </p>
 *
 * @author HM
 * @since 2023-05-25
 */
@Service
public class ApArticleContentServiceImpl extends ServiceImpl<ApArticleContentMapper, ApArticleContent> implements ApArticleContentService {

    @Override
    public void saveContent(Long articleId, String content) {
        // 有就update 没有insert
        ApArticleContent contentDB = this.getById(articleId);
        if(contentDB == null){
            ApArticleContent toBeInsert = new ApArticleContent();
            toBeInsert.setArticleId(articleId);
            toBeInsert.setContent(content);
            this.save(toBeInsert);
        }else{
            ApArticleContent toBeUpate = new ApArticleContent();
            toBeUpate.setContent(content);
            toBeUpate.setArticleId(articleId);
            this.updateById(toBeUpate);
        }
    }
}
